<html>
<head>
<title>pyvnc2swf</title>
</head>
<body>

<h1>pyvnc2swf</h1>
<p>
<a href="index.html">back</a>
<a href="pyvnc2swf-j.html">[Japanese]</a>
<p>
Homepage: <a href="http://www.unixuser.org/~euske/vnc2swf/">http://www.unixuser.org/~euske/vnc2swf/</a><br>
Discussion: <a href="http://lists.sourceforge.net/lists/listinfo/vnc2swf-users">http://lists.sourceforge.net/lists/listinfo/vnc2swf-users</a>
<p>
$Id: pyvnc2swf.html,v 1.2 2008/11/16 02:39:40 euske Exp $
<hr noshade>
<p>
Pyvnc2swf is a cross-platform screen recording tool.
It captures screen motion through VNC protocol and generates a Shockwave Flash (SWF) movie.
Pyvnc2swf suite comes with three Python programs:
<ul>
<li> <a href="#vnc2swf"><code>vnc2swf.py</code></a> - Recorder
<li> <a href="#edit"><code>edit.py</code></a> - Movie editor 
(This is NOT a general SWF file editor. It only supports movies generated by vnc2swf.)
<li> <a href="#play"><code>play.py</code></a> - Simple movie viewer
</ul>

<p>
For questions, please read the <a href="#faq">FAQ</a> and
<a href="http://sourceforge.net/mailarchive/forum.php?forum=vnc2swf-users">list archives</a>
before sending me emails.

<p>
<strong>Terms and Conditions:</strong>
Pyvnc2swf comes with ABSOLUTELY NO WARRANTY. 
This software is distributed under the GNU General Public License.

<hr noshade>

<h3>Installation</h3>

<p>In all platforms, the following packages are required:
<ul>
<li> <a href="http://www.python.org/">Python</a> (2.4 or above)
<li> <a href="http://www.pygame.org/">Pygame</a> (1.6 or above)
<li> Optional: <a href="http://pymedia.org/">PyMedia</a> (1.3.5 or above - required for mpeg encoding)
</ul>
<p>
In most Linux distros, these packages are readily available.
In Mac OS X, you would need an additional 
<a href="http://pythonmac.org/packages/">OS X build of Pygame package</a>.
<p>
Also, you need at least one VNC server:
<ul>
<li> <a href="http://www.realvnc.com/">RealVNC</a> or <a href="http://www.tightvnc.com/">TightVNC</a> (Unix, Linux or Windows)
<li> <a href="http://www.karlrunge.com/x11vnc/#downloading">x11vnc</a> (Unix/Linux for recording an existing desktop)
<li> <a href="http://www.redstonesoftware.com/vnc.html">OSXVnc</a> (Mac OS X)
<li> GNOME Vino
(This is not an independent package, but if you have GNOME desktop environment
which supports remote desktop functionality, you have it.)
</ul>

<a name="vnc2swf">
<hr noshade>
<h3>Recording</h3>
<p>
<code><strong>vnc2swf.py</strong></code> program
captures a VNC sessions and records it in either SWF or VNCLog format.
This is a VNC client and communicates directly with a VNC server.
A user need to start a VNC server in advance.
<p>
<code>vnc2swf.py</code> runs in two different modes: 
GUI (Graphical User Interface) mode and CLI (Command Line Interface) mode.
In the GUI mode, start recording by clicking the "Start" button.
Then choose the "Save as..." command from the "File" menu to save 
the recorded movie to a file.
In the CLI mode, a user needs to specify the output filename from command line. 
Recording is started immediately. In both modes, a user is
prompted for a VNC password if the server requires authentication
(and unless the user doesn't specify the password file).
In the CLI mode, hit Control-C to stop recording. 
After finishing recording, it generates two files with the specified name:
a <code>.swf</code> and <code>.html</code> file.
The <code>.html</code> file contains an HTML tag and a javascript code
to provide seek bar function.
<p>
A user can choose three different methods to encode movie image:
"<code>flv</code>", "<code>swf5</code>", "<code>swf7</code>", "<code>mpeg</code>" (PyMedia required), 
or "<code>vnc</code>".
The first <code>swf5</code> encoding (default) provides a reasonable movie size.
The second encoding method, <code>swf7</code> provides a smaller SWF movie. 
This is, however, not recommended to use within <code>vnc2swf.py</code> for
two reasons: This type of encoding is only supported by Flash Player
version 7 or newer. Also, generating a movie with on-the-fly 
<code>swf7</code> encoding is slower so you might experience frame dropping.
Actually, you can convert a <code>swf5</code>-encoded movie into <code>swf7</code>-encoded
one after recording by using <code>edit.py</code>, so anyway you don't need to 
use this method when recording. The third encoding method is <code>vnc</code>.
This method generates a <code>.vnc</code> (VNCLog) file, which is compatible with
<a href="http://www.sodan.org/~penny/vncrec/">vncrec</a> output file.
You can convert it to a SWF movie with <code>edit.py</code>.
A <code>.vnc</code> file is not a SWF movie by itself, but its encoding is the fastest. 
<p>
<strong>NOTE:</strong>
Unlike the C version, <code>vnc2swf.py</code> doesn't handle any
user interaction. If you want to control the server's desktop,
you need to launch vncviewer or its equivalent separately.

<h4>Syntax</h4>
<ul>
<li> <strong>(GUI)</strong> <code>$ vnc2swf.py [-o <u>filename</u>] [<u>options</u>] [<u>host[:display]</u> [<u>port</u>]]</code>
<li> <strong>(CLI)</strong> <code>$ vnc2swf.py -n -o <u>filename</u> [<u>options</u>] [<u>host[:display]</u> [<u>port</u>]]</code>
</ul>

<h4>Example</h4>
<blockquote><pre>
<em>(Record a virtual screen)</em>
$ <strong>vncserver -geometry 640x480</strong>
$ <strong>vnc2swf.py -o out.swf localhost:1</strong>

<em>(Record an existing screen)</em>
$ <strong>x11vnc -localhost -viewonly -wait 10 -defer 10 -bg</strong>
$ <strong>vnc2swf.py -o out.swf localhost:0</strong>

<em>(Record a remote screen)</em>
$ <strong>vnc2swf.py -n -o out.flv vnc.example.com:1</strong>

</blockquote>

<p> If you're using x11vnc, see also <a href="recordwin.html">recordwin</a>.
This is a convenient script to record a particular window.

<h4>Recording Tips</h4>
<ul>
<li> Use as small screen size as possible, or try to specify the smallest clipping rectangle.
With a large screen, VNC's screen polling gets slower and 
vnc2swf also gets slower for converting bigger images. 
Using a small screen also helps reducing the movie size.
<li> Reducing the framerate sometimes helps reducing the movie size.
If the generated movie is still very big, try resampling frames or
scaling the image with <code>edit.py</code>.
<li> To record a long movie (more then 20min.), the only available option is 
to use <code>flv</code> (or <code>mpeg</code> if you have PyMedia).
<code>swf5</code> or <code>swf7</code> files have a limitation and
lcan have up to 16000 frames, which is roughly 22 minutes.
<li> If you experience frame dropping, try changing the server options for screen polling (if any).
If you're using <code>x11vnc</code>, try adding <code>-wait 10 -defer 10</code>.
<li> When recording <code>flv</code> movie, you can dump a live stream output
to stdout by speficing '<code>-</code>' as a filename. But currently I have no idea
how to use. (broadcasting your desktop on the web?)
</ul>

<h4>Options</h4>
<dl>
<dt> <code>-n</code>
<dd> Console mode (no GUI).
<p>
<dt> <code>-o <u>outputfile</u></code>
<dd> Specifies the output filename. This option is required in CLI mode.
In GUI mode, when not specified it prompts the user for the filename.
The movie encoding type is usually inferred from the filename, so
the filename should end with either "<code>.swf</code>" or "<code>.vnc</code>".
Otherwise, the user need to specify the output movie encoding with <code>-t</code> option
(see below.)
<p>
<dt> <code>-C <u>clipping</u></code>
<dd> Specifies the clipping rectangle.  
The geometry must be as form of "<code><u>width</u>x<u>height</u>+<u>left</u>+<u>top</u></code>"
(e.g. "<code>400x300+120+0</code>").
Unlike other X11 applications, all rectangular components are required. Negative values are not supported.
<p>
<dt> <code>-r <u>framerate</u></code>
<dd> Specifies the framerate in fps. (default=12.0)
<p>
<dt> <code>-t <u>encodingtype</u></code> 
<dd> Specifies the output movie encoding method
("<code>flv</code>", "<code>mpeg</code>", "<code>swf5</code>", "<code>swf7</code>" or "<code>vnc</code>").
When omitted, the encoding type is automatically inferred from the filename
(<code>*.swf</code> = swf5, <code>*.vnc</code> = vnc).
<p>
<dt> <code>-N</code> 
<dd> Disables cursor pseudo-encoding. Pyvnc2swf normally tries to use 
cursor pseudo-encoding to capture a mouse cursor position
so that a cursor can be moved separately from a screen image
and it reduces the movie size. However this might not work with
some vnc servers. This option can be used for disabling the function.
<p>
<dt> <code>-P <u>passwdfile</u></code>
<dd> Specifies a password file. If specified, its content is automatically
loaded and supplied as password when a VNC server requires it.
A password file contains an encrypted password string and
can be created with <code>vncpasswd</code>. A user can directly specify
<code>~/.vnc/passwd</code>, which normally contains the password 
for the local vnc server.
<p>
<dt> <code>-e <u>vncencodings</u></code>
<dd> Specifies the preferred encodings for VNC image transfer
(this is different from movie encoding).
Normally you don't need to change this option.
Encodings are comma-separated integers (default="5,4,0").
Changing encodings might improve recording performance.
<p>
<dt> <code>-S <u>subprocess</u></code> (Supported on Un*x only, Python 2.4 or above is required) 
<dd> Set a command to run during recording. 
This option is useful for recording voice with a separated program.
A command line is a space-separated sequence of arguments 
which are passed to a child process like a usual shell command line.
However the command line is not passed to a shell and the arguments are directly passed
to the child process without any substitution. A child process is started
immediately after recording starts and sent SIGINT after recording finishes.
<p>
<dt> <code>-d</code>
<dd> Increases debug level.
<p>
</dl>

<a name="edit">
<hr noshade>
<h3>Editing</h3>
<p>
<code><strong>edit.py</strong></code> program is for editing or reorganizing one or multiple movies
generated by <code>vnc2swf.py</code>. This program also supports converting
a .vnc file into .swf movie, changing the encoding method (swf5-&gt;swf7),
attaching MP3 audio file to a movie, extracting
images from a movie and resampling/scaling/clipping a movie image.
<p>
<code>edit.py</code> currently supports only command line interface.
The user must give one output filename and one or more input filename(s).
Input movies are concatenated sequentially (in the specified order)
and the desired effects are applied.
<p>

<h4>Syntax</h4>
<p>
<code>$ edit.py -o <u>outfile.swf</u> [<u>options</u>] <u>infile</u> ...</code>

<h4>Example</h4>
<blockquote><pre>
<em>(Convert .vnc file into .swf with compressed video encoding)</em>
$ <strong>edit.py -o out.swf -c -t swf7 input.vnc</strong>

<em>(Attach an mp3 file to .swf)</em>
$ <strong>edit.py -o out.swf -a voice.mp3 in.swf</strong>

<em>(Concatenate two movies and extract the frames into another movie)</em>
$ <strong>edit.py -o out.swf -f 100-200,350- movie1.swf movie2.swf</strong>

<em>(Clip the top left area of the movie and shrink it to half the size)</em>
$ <strong>edit.py -o small.swf -C 320x240+0+0 -s 0.5 in.swf</strong>

<em>(Convert .swf into MPEG)</em>
$ <strong>edit.py -o out.mpg input.swf</strong>

<em>(Convert .swf into .flv)</em>
$ <strong>edit.py -o out.flv input.swf</strong>
</pre></blockquote>


<h4>Options</h4>
<dl>
<dt> <code>-o <u>outputfile</u></code>
<dd> Specifies the output filename. This option is always required.
<p>
<dt> <code>-c</code>
<dd> Compress a movie with zlib. Compressions is supported for 
both (<code>swf5</code> and <code>swf7</code>) types of movies, but
usually it's most effective when applied to <code>swf7</code>-encoded movies.
<p>
<dt> <code>-t <u>encodingtype</u></code> 
<dd> Specifies the encoding method for an output movie.
When this option is not specified, the encoding type is inferred
from the output filename extention.
<p>
<table>
<tr><th>Type</th><th>Extension</th><th>Description</th></tr>
<tr><td><code>swf5</code></td><td><code>.swf</code></td><td>SWF movie (default)</td></tr>
<tr><td><code>swf7</code></td><td></td><td>SWF movie with stream video encoding support</td></tr>
<tr><td><code>flv</code></td><td><code>.flv</code></td><td>FLV movie</td></tr>
<tr><td><code>mpeg</code></td><td><code>.mpg</code></td><td>MPEG movie (requires <a href="http://pymedia.org/">PyMedia</a>)</td></tr>
<tr><td><code>bmp</code></td><td><code>.bmp</code></td><td>BMP image sequence</td></tr>
<tr><td><code>png</code></td><td><code>.png</code></td><td>PNG image sequence</td></tr>
</table>
<p>
Note that <code>swf7</code> encoding is supported only with Flash Player version 7 or newer.
<p>
<dt> <code>-f <u>frames</u></code> <em>or</em>
<br> <code>-F <u>frames</u></code>
<dd> Specifies a sequence of frames presented in the output movie. 
When omitted, all frames are presented in the original order (default).
Frames can be specified with a comma-separated list of integers.
A range of integers can be also specified by using <code>-</code> (hyphen) sign.
For example: <code>10,200,300-400</code> specifies the frames whose number is 10 and 200,
plus every frame between frame 300 and 400. The beginning (or ending) frame number can be omitted
(e.g. <code>-100</code> or <code>300-</code>). In this case, the first (or last) frame number is used
as the other end of the range.
<p>
<code>-F</code> option and <code>-f</code> option is same except that <code>-F</code> doesn't 
chop the audio while <code>-f</code> does. When you're putting audio on the movie, if
you use <code>-f</code> and <code>-a</code> option at the same time, it chops an mp3 file
according to the selected frames. However, when you want to cast a continuous sound (such as music) 
onto a whole movie, this might not be the desired effect. In such a case, use <code>-F</code> 
instead of <code>-f</code>.
<p>
<dt> <code>-a <u>mp3file</u></code>
<dd> Attaches mp3 file(s) to the movie. (Adding audio to FLV format is currently not supported.)
Multiple mp3 files are concatenated in the specified order.
<br>
<strong>NOTE:</strong> When specifying multiple mp3 files,
make sure every file has the same bitrate as the first one.
And do NOT use "variable bitrate" (VBR) mp3 files,
as the SWF format doesn't support them!
<p>
<dt> <code>-s <u>scaling</u></code>
<dd> Rescale the movie image with a specified ratio
which is given as a fraction.
<br>
<strong>NOTE:</strong> There will be noises with non-multiple scaling (e.g. 0.7).
<p>
<dt> <code>-C <u>clipping</u></code>
<dd> Clips the movie into a specified rectangle.
The geometry must be as form of "<code><u>width</u>x<u>height</u>+<u>left</u>+<u>top</u></code>"
(e.g. "<code>400x300+120+0</code>").
<p>
<dt> <code>-K <u>keyinterval</u></code>
<dd> Insert a keyframe in every <em>N</em> frames.
Keyframes work as hints for Flash Player and are useful for
seeking a frame within a long movie.
When the number of total frames exceeds 10,000, inserting
keyframes in every 500 frames (<code>-K 500</code>) is recommended.
<p>
<dt> <code>-r <u>framerate</u></code>
<dd> Changes the frame rate of the movie. This option itself doesn't do any frame resampling
and simply changes the movie speed. When this option is omitted, <code>edit.py</code> tries
to keep the original frame rate in the output movie.
<p>
<dt> <code>-R <u>resampleframes</u></code>
<dd> Resample (or "thin down") a movie by picking one from every <em>N</em> frames.
<p>
<dt> <code>-S <u>skipmp3frames</u></code>
<dd> Skip the first <em>N</em> mp3-frames of the mp3 file.
When '<code>s</code>' is appended to the number (such as '<code>1.0s</code>'),
it indicates the number of seconds instead of frames.
This option is useful when there is a time lag between a
recorded image and audio.
<p>
<dt> <code>-B <u>blocksize</u></code>
<dd> Sets the blocksize for <code>swf7</code> or <code>flv</code> encoding method (default=32).
This must be a multiple of 16.
<p>
<dt> <code>-b</code>
<dd> Suppress a seekbar in a generated html file.
<p>
<dt> <code>-l</code>
<dd> Disables movie loop in a generated html file.
<p>
<dt> <code>-d</code>
<dd> Increases debug level.
<p>
</dl>

<a name="play">
<hr noshade>
<h3>Previewing</h3>
<p>
<strong><code>play.py</code></strong> is a simple player for a <code>.swf</code> or <code>.vnc</code> file.
This program might be useful for spotting the right frame number in a recorded movie.
However its speed is awkward and audio output is not supported.
It only supports vnc2swf-generated files and cannot play general SWF movies.
<p>
The player accepts the following keys:
<ul>
<li> Space / Enter / mouse click: Toggle Play/Stop.
<li> Left / Right / dragging a seek bar: Skip frames.
<li> "<code>q</code>" / Escape: Quit.
<li> "<code>s</code>": Take a snapshot. The image is saved as "<code><u>inputfile</u>-<u>frameno</u>.bmp</code>".
</ul>

<h4>Syntax</h4>
<p>
<code>$ play.py [<u>options</u>] <u>moviefile</u> ...</code>

<h4>Options</h4>
<dl>
<dt> <code>-r <u>framerate</u></code>
<dd> Specifies the framerate to play.
<p>
<dt> <code>-s <u>scaling</u></code>
<dd> Specifies the scaling ratio with a fraction.
<p>
<dt> <code>-C <u>clipping</u></code>
<dd> Specifies the clipping rectangle.
The geometry must be as form of "<code><u>width</u>x<u>height</u>+<u>left</u>+<u>top</u></code>"
(e.g. "<code>400x300+120+0</code>").
<p>
<dt> <code>-d</code>
<dd> Increases debug level.
<p>
</dl>

<a name="faq">
<hr noshade>
<h3>Frequently Asked Questions</h3>
<dl>
<dt> <strong>I found weird artifacts in a recorded movie. How to fix it?</strong>
<dd> Probably you played the SWF file directly. 
A SWF movie should be played <u>in the exactly same size</u> as it is recorded.
Use an HTML file generated by <code>vnc2swf.py</code> or <code>edit.py</code>. 
<p>
<dt> <strong>How to make a movie with audio?</strong>
<dd> Record your audio separately and encode it with an MP3 encoder
like <a href="http://lame.sourceforge.net/">Lame</a>.
Then combine them with <code>edit.py</code>.
<p>
<dt> <strong>A browser freezes when I try to seek within a movie.</strong>
<dd> Put keyframes in every hundreds frame. Try <code>-K</code> option in <code>edit.py</code>.
Normally putting keyframes in every 500 frames (<code>-K 500</code>) gives a reasonable result.
<p>
</dl>

<a name="structure">
<hr noshade>
<h3>Structure of the Program</h3>
<p>
For those who are interested in learning or extending the program,
I drew
<a href="http://www.unixuser.org/~euske/vnc2swf/pyvnc2swf-flow.png">a simple figure to explain how data goes between objects within pyvnc2swf</a>.


<hr noshade>
<address>
Yusuke Shinyama
<code>&lt;yusuke at cs dot nyu dot edu&gt;</code>
</address>
</body>
</html>
